package services.core;

import java.util.HashMap;
import java.util.Map;

import models.core.user.CredentialDto;
import models.core.user.UserDto;
import models.core.user.UserDtoInfo;
import play.libs.F.Promise;
import play.libs.WS;
import services.ServiceException;

public class UserService extends CoreService {
	
	public static void addFavorite(String token, String entity, String id) throws ServiceException {
		Map<String,String> queryParams = new HashMap<String,String>();
		queryParams.put("token",token);
		WS.Response r = put("/user/favorite/" + entity + "/" + id, null, queryParams).get();
		if( r.getStatus() != 200){
			throw new ServiceException(r.getBody());
		}
	}
	
	public static Promise<String> create(UserDto user) throws ServiceException {
		return post( String.class,  "/user/create", user, null, null);
	}
	
	public static Promise<String> authenticate(CredentialDto credential) throws ServiceException {
		return put( String.class,  "/user/token", credential, null, null);
	}

	public static Promise<UserDtoInfo> getUserInfo(String token) {
		Map<String,String> queryParams = new HashMap<String,String>();
		queryParams.put("token",token);
		return get(UserDtoInfo.class, "/user/info", null, queryParams);
	}	 
}
